<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;

class IndexController extends Controller
{
	// 主页顶部的数据
	public function index()
	{
		$link = DB::table('links')->get();
		$lo = DB::table('logo')->get();
		$logo = $lo[0]->set;
		$logopic = $lo[0]->logo;
		if ($logo == 0) {
			$datatop = DB::table('classone')
					->where([['level','=',1],['status','=','0']])
					->select('level','classname','oneid','status')
					->get()
					->all();
			// dd($datatop);
			// dd($data['status']);
			foreach ($datatop as $k => $v) {
				$classname = $v->classname;
				$listtop["$classname"] = DB::table('classone')
						->where([['level','=',2],['cid','=',$v->oneid]])
						->join('goods','goodsname','=','classname')
						->select('goods.*')
						->get()
						->all();
			}
			 // dd($listtop);
			$listleft = DB::table('classone')
					->where([['level','=',1],['status','=','1']])
					->select('level','classname','oneid','status')
					->get()
					->all();
			foreach ($listleft as $k => $v) {
				$classname = $v->classname;
				$listle["$classname"] = DB::table('classone')
						->where([['level','=',2],['cid','=',$v->oneid]])
						->join('goods','goodsname','=','classname')
						->select('goods.*')
						->get()
						->all();
			}
			// dd($listleft);
			// dd($listtop);
			// dd($datagoods);
	  		// return view('home\index',['listtop'=>$listtop,'datagoods'=>$datagoods,'list'=>$list,]);
	  		$listeven = DB::table('classeven')->where('level','=',1)->get()->all();
	  		foreach ($listeven as $k => $v) {
	  			$classname = $v->classname;
	  			$cid = $v->evenid;
	  			$listtwo["$classname"] =  DB::table('classeven')
	  					->where([['level','=',2],['cid','=',$cid]])
	  					->join('goods','goodsname','=','classname')
	  					->select('goods.*')
	  					->get();
	  		   // dd($listtwo);
	  		}
	  		// dd($listtwo);
	  		$listodd = DB::table('classodd')->where('level','=',1)->get()->all();
	  		foreach ($listodd as $k => $v) {
	  			$classname = $v->classname;
	  			$cid = $v->oddid;
	  			$listo["$classname"] = DB::table('classodd')
	  				->where([['level','=',2],['cid','=',$cid]])
	  				->join('goods','goodsname','=','classname')
	  				->select('goods.*')
	  				->get();
	  		}
	  		// dd($listo);
	  		// 图片轮播图查询=======================
	  		$picscroll = DB::table('picscroll')->get(); 
	  		// dd($listleft);
	  		// dd($listle);
			return view('home.index',['datatop'=>$datatop,'listtop'=>$listtop,'listleft'=>$listleft,'listle'=>$listle,'listeven'=>$listeven,'listtwo'=>$listtwo,'listodd'=>$listodd,'listo'=>$listo,'picscroll'=>$picscroll,'link'=>$link]);
		}else{
			return view('home.logo',['logopic'=>$logopic]);
		}
	}

}
